package com.yunhe.merchants.service.impl;

import com.yunhe.common.metadata.BaseExcelModel;
import com.yunhe.common.model.mybatis.PageResult;
import com.yunhe.merchants.constant.MyProjectConsts;
import com.yunhe.merchants.domain.MyProject;
import com.yunhe.merchants.model.FilterCondition;
import com.yunhe.merchants.model.HistoryProjectUpload;
import com.yunhe.merchants.model.IntentionProjectUpload;
import com.yunhe.merchants.service.IHistoryProjectService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @Author: DongWenYu
 * @Date: 2021/5/7 21:06
 */
@Service
public class HistoryProjectServiceImpl extends MyProjectServiceImpl implements IHistoryProjectService {

    private List<String> status = new ArrayList<>();

    private static final Logger logger = LoggerFactory.getLogger(HistoryProjectServiceImpl.class);

    @PostConstruct
    private void init(){
        Collections.addAll(status, MyProjectConsts.COMPANY_STATUS.Leave.value(),MyProjectConsts.COMPANY_STATUS.Fail.value());
    }
    @Override
    public PageResult selectByFilterCondition(FilterCondition filterCondition, Long userId, int page, int size) {
        return super.selectByFilterCondition(filterCondition,status,userId,page,size);
    }

    @Override
    public void upload(List<HistoryProjectUpload> historyProjectUploads, Long userId, Long stationId) {
        //upload转Do
        List<MyProject> myProjects = convertUploadToDo(historyProjectUploads,userId,stationId);
        //批量插入
        myProjectRepository.insertBatch(myProjects);
        logger.info("导入{}条数据进入数据库",myProjects.size());
    }

    @Override
    public List<MyProject> export(String ids, FilterCondition filterCondition) {
        return super.export(ids,filterCondition,status);
    }

    @Override
    public MyProject update(Long id, String leavingReason, String latestDestination, Long userId) {
        MyProject myProject = myProjectRepository.selectById(id);
        myProject.setLatestDestination(latestDestination);
        myProject.setLeavingReason(leavingReason);
        this.update(myProject,userId);
        return myProject;
    }

}
